<?php
/**
 * Created by PhpStorm.
 * User: xaq
 * Date: 2017/5/19
 * Time: 16:56
 */

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\validate\IDCollection;
use app\api\validate\IDMustBePostiveInt;
use think\Controller;
use app\api\model\Theme as ThemeModel;
use app\lib\exception\ThemeException;

class Theme extends BaseController
{
    /**
     * @url /theme?ids=id1,id2,id3..
     */
    public function getSimpleList($ids=''){
        (new IDCollection()) ->goCheck();
        $ids = explode(',',$ids);
        $result = ThemeModel::with('topicImg,headImg')
            ->select($ids);
        if($result->isEmpty()) {
            throw new ThemeException();  //自定义抛出异常
        }
        return $result;
    }

    /**
     * @url /theme/:id
     */
    public function getComplexOne($id) {
        (new IDMustBePostiveInt()) ->goCheck();
        $theme = ThemeModel::getThemeWithProducts($id);
        if(!$theme) {
            throw new ThemeException();
        }
        return $theme;
    }

}